package com.common.dongqiuhui.apps.comm.service;

import android.app.Application;
import android.content.Context;

import com.common.dongqiuhui.apps.comm.net.BallPhotoHttp;
import com.common.dongqiuhui.apps.comm.tools.BallLog;

/**
 * 公共Application<br>
 * 包含:<br>
 * @author sam
 * 
 */
public class BaseBallApplication extends Application {
	private static BaseBallApplication instance;
	/**
	 * 应用ID
	 */
	private String mAppId = "";
	
	/**
	 * 应用是否在前台
	 */
	private static boolean mIsActive = false;

    private static Context context;


    public static Context getContext() {
        return context;
    }



     public static BaseBallApplication getApplication(){
    	 return instance;
     }
	/**
	 * 如果子类重写此方法,一定要调用super.onCreate();
	 */
	@Override
	public void onCreate() {
		super.onCreate();
        context  = getApplicationContext();
        instance=this;
		BallPhotoHttp.setContext(this);
	}
	/**
	 * 如果子类重写此方法,一定要调用super.onTerminate();
	 */
	@Override
	public void onTerminate() {
		super.onTerminate();
		BallLog.d("Application onTerminate.");
	}

	/**
	 * 如果子类重写此方法,一定要调用super.onTerminate();
	 */
	@Override
	public void onLowMemory() {
		super.onLowMemory();
		System.gc();
	}

	/**
	 * 设置AppId,需要在程序启动的时候调用,super.onCreate之前<Br>
	 * 同时设置接口请求需要的Appid
	 * 
	 * @author wangshuaibo
	 * @param appId
	 * @throws Exception
	 */
	protected void setAppId(String appId) {
		mAppId = appId;
		//PlayingHttp.setAppId(mAppId);
		// 设置appId
		BallLog.d("Application setAppId.");
	}

	public static boolean isActive(){
		return mIsActive;
		
	}
	
	public static void setActive(boolean isActive){
		mIsActive = isActive;
	}

	private static ApplicationListener mApplicationListener = null;

	public static void setApplicationListener(ApplicationListener listener) {
		mApplicationListener = listener;
	}

	public static void onGoToBackgroud() {
		if (mApplicationListener != null) {
			mApplicationListener.onGoToBackgroud();
		}
	}

	public static void onGoToForegroud() {
		if (mApplicationListener != null) {
			mApplicationListener.onGoToForeground();
		}

	}
	public static interface ApplicationListener {

		/**
		 * 应用进入后台
		 */
		public void onGoToBackgroud();

		/**
		 * 应用恢复展示
		 */
		public void onGoToForeground();
	}

}
